<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>eRPC API Reference: erpc_static_queue.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="nxp_logo_small.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">eRPC API Reference
   &#160;<span id="projectnumber">Rev. 1.7.4</span>
   </div>
   <div id="projectbrief">NXP Semiconductors</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>API&#160;Reference</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('erpc__static__queue_8h_source.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">erpc_static_queue.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="erpc__static__queue_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/*</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"> * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"> * Copyright 2016 NXP</span></div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * All rights reserved.</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> *</span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> *</span></div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> * SPDX-License-Identifier: BSD-3-Clause</span></div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment"> */</span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;</div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="preprocessor">#ifndef __embedded_rpc__static_queue__</span></div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#define __embedded_rpc__static_queue__</span></div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;</div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="preprocessor">#include &lt;cstring&gt;</span></div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;</div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="comment">// Classes</span></div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespaceerpc.html">erpc</a> {</div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">class</span> T, u<span class="keywordtype">int</span>32_t elementCount&gt;</div><div class="line"><a name="l00032"></a><span class="lineno"><a class="line" href="classerpc_1_1_static_queue.html">   32</a></span>&#160;<span class="keyword">class </span><a class="code" href="classerpc_1_1_static_queue.html">StaticQueue</a></div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;{</div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;<span class="keyword">public</span>:</div><div class="line"><a name="l00040"></a><span class="lineno"><a class="line" href="classerpc_1_1_static_queue.html#a248662ae7d3a228d056332389739b941">   40</a></span>&#160;    <a class="code" href="classerpc_1_1_static_queue.html#a248662ae7d3a228d056332389739b941">StaticQueue</a>(<span class="keywordtype">void</span>)</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;    {</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;        <a class="code" href="classerpc_1_1_static_queue.html#a0c43f1fba589c88fbb22a0e8b237d58c">m_capacity</a> = elementCount;</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;        <a class="code" href="classerpc_1_1_static_queue.html#aa5b8df6fb776578ca3d8ddf5b4187af2">m_head</a> = 0;</div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;        <a class="code" href="classerpc_1_1_static_queue.html#af18992edddaa6bfb26713fde997273b8">m_tail</a> = 0;</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;    }</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;</div><div class="line"><a name="l00052"></a><span class="lineno"><a class="line" href="classerpc_1_1_static_queue.html#a24ddc2195588cee38e390652f9a6d070">   52</a></span>&#160;    <a class="code" href="classerpc_1_1_static_queue.html#a24ddc2195588cee38e390652f9a6d070">~StaticQueue</a>(<span class="keywordtype">void</span>) {}</div><div class="line"><a name="l00061"></a><span class="lineno"><a class="line" href="classerpc_1_1_static_queue.html#ab1fe280f10fdf322ae75f16d80b812cc">   61</a></span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="classerpc_1_1_static_queue.html#ab1fe280f10fdf322ae75f16d80b812cc">add</a>(T element)</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;    {</div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;        <span class="keywordflow">if</span> ((<a class="code" href="classerpc_1_1_static_queue.html#aa5b8df6fb776578ca3d8ddf5b4187af2">m_head</a> + 1) % <a class="code" href="classerpc_1_1_static_queue.html#a0c43f1fba589c88fbb22a0e8b237d58c">m_capacity</a> != <a class="code" href="classerpc_1_1_static_queue.html#af18992edddaa6bfb26713fde997273b8">m_tail</a>)</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;        {</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;            std::memcpy(<a class="code" href="classerpc_1_1_static_queue.html#ad10392812527307c0f7b411fd5ceb8ee">m_storage</a>[<a class="code" href="classerpc_1_1_static_queue.html#aa5b8df6fb776578ca3d8ddf5b4187af2">m_head</a>], &amp;element, <span class="keyword">sizeof</span>(T));</div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;            m_head = (m_head + 1) % <a class="code" href="classerpc_1_1_static_queue.html#a0c43f1fba589c88fbb22a0e8b237d58c">m_capacity</a>;</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;            <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;        }</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;    }</div><div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;</div><div class="line"><a name="l00080"></a><span class="lineno"><a class="line" href="classerpc_1_1_static_queue.html#a50621cf1d1676983bbf95c7dbf178229">   80</a></span>&#160;    <span class="keywordtype">bool</span> <span class="keyword">get</span>(T *element)</div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;    {</div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;        <span class="keywordflow">if</span> (<a class="code" href="classerpc_1_1_static_queue.html#af18992edddaa6bfb26713fde997273b8">m_tail</a> != <a class="code" href="classerpc_1_1_static_queue.html#aa5b8df6fb776578ca3d8ddf5b4187af2">m_head</a>)</div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;        {</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;            std::memcpy(element, <a class="code" href="classerpc_1_1_static_queue.html#ad10392812527307c0f7b411fd5ceb8ee">m_storage</a>[<a class="code" href="classerpc_1_1_static_queue.html#af18992edddaa6bfb26713fde997273b8">m_tail</a>], <span class="keyword">sizeof</span>(T));</div><div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;            m_tail = (m_tail + 1) % <a class="code" href="classerpc_1_1_static_queue.html#a0c43f1fba589c88fbb22a0e8b237d58c">m_capacity</a>;</div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;            <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;        }</div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;    }</div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;</div><div class="line"><a name="l00096"></a><span class="lineno"><a class="line" href="classerpc_1_1_static_queue.html#a90d03fc6a09db2f2e9ad4f722ba81547">   96</a></span>&#160;    <span class="keywordtype">int</span> <a class="code" href="classerpc_1_1_static_queue.html#a90d03fc6a09db2f2e9ad4f722ba81547">size</a>(<span class="keywordtype">void</span>)</div><div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;    {</div><div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;        <span class="keywordflow">if</span> (<a class="code" href="classerpc_1_1_static_queue.html#aa5b8df6fb776578ca3d8ddf5b4187af2">m_head</a> &gt;= <a class="code" href="classerpc_1_1_static_queue.html#af18992edddaa6bfb26713fde997273b8">m_tail</a>)</div><div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;        {</div><div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;            <span class="keywordflow">return</span> <a class="code" href="classerpc_1_1_static_queue.html#aa5b8df6fb776578ca3d8ddf5b4187af2">m_head</a> - <a class="code" href="classerpc_1_1_static_queue.html#af18992edddaa6bfb26713fde997273b8">m_tail</a>;</div><div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;        }</div><div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;        <span class="keywordflow">return</span> (<a class="code" href="classerpc_1_1_static_queue.html#a0c43f1fba589c88fbb22a0e8b237d58c">m_capacity</a> - <a class="code" href="classerpc_1_1_static_queue.html#af18992edddaa6bfb26713fde997273b8">m_tail</a> + <a class="code" href="classerpc_1_1_static_queue.html#aa5b8df6fb776578ca3d8ddf5b4187af2">m_head</a>);</div><div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;    }</div><div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;</div><div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;<span class="keyword">protected</span>:</div><div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;    uint64_t <a class="code" href="classerpc_1_1_static_queue.html#ad10392812527307c0f7b411fd5ceb8ee">m_storage</a>[elementCount][(<span class="keyword">sizeof</span>(T) + <span class="keyword">sizeof</span>(uint64_t) - 1) /</div><div class="line"><a name="l00107"></a><span class="lineno"><a class="line" href="classerpc_1_1_static_queue.html#ad10392812527307c0f7b411fd5ceb8ee">  107</a></span>&#160;                                     <span class="keyword">sizeof</span>(uint64_t)]; </div><div class="line"><a name="l00109"></a><span class="lineno"><a class="line" href="classerpc_1_1_static_queue.html#a0c43f1fba589c88fbb22a0e8b237d58c">  109</a></span>&#160;    uint32_t <a class="code" href="classerpc_1_1_static_queue.html#a0c43f1fba589c88fbb22a0e8b237d58c">m_capacity</a>;                                </div><div class="line"><a name="l00110"></a><span class="lineno"><a class="line" href="classerpc_1_1_static_queue.html#aa5b8df6fb776578ca3d8ddf5b4187af2">  110</a></span>&#160;    uint32_t <span class="keyword">volatile</span> <a class="code" href="classerpc_1_1_static_queue.html#aa5b8df6fb776578ca3d8ddf5b4187af2">m_head</a>;                           </div><div class="line"><a name="l00111"></a><span class="lineno"><a class="line" href="classerpc_1_1_static_queue.html#af18992edddaa6bfb26713fde997273b8">  111</a></span>&#160;    uint32_t <span class="keyword">volatile</span> <a class="code" href="classerpc_1_1_static_queue.html#af18992edddaa6bfb26713fde997273b8">m_tail</a>;                           </div><div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;};</div><div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;</div><div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;} <span class="comment">// namespace erpc</span></div><div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;</div><div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;<span class="preprocessor">#endif // defined(__embedded_rpc__static_queue__)</span></div><div class="ttc" id="classerpc_1_1_static_queue_html_aa5b8df6fb776578ca3d8ddf5b4187af2"><div class="ttname"><a href="classerpc_1_1_static_queue.html#aa5b8df6fb776578ca3d8ddf5b4187af2">erpc::StaticQueue::m_head</a></div><div class="ttdeci">uint32_t volatile m_head</div><div class="ttdef"><b>Definition:</b> erpc_static_queue.h:110</div></div>
<div class="ttc" id="classerpc_1_1_static_queue_html_a248662ae7d3a228d056332389739b941"><div class="ttname"><a href="classerpc_1_1_static_queue.html#a248662ae7d3a228d056332389739b941">erpc::StaticQueue::StaticQueue</a></div><div class="ttdeci">StaticQueue(void)</div><div class="ttdoc">Constructor of StaticQueue class. </div><div class="ttdef"><b>Definition:</b> erpc_static_queue.h:40</div></div>
<div class="ttc" id="classerpc_1_1_static_queue_html_a90d03fc6a09db2f2e9ad4f722ba81547"><div class="ttname"><a href="classerpc_1_1_static_queue.html#a90d03fc6a09db2f2e9ad4f722ba81547">erpc::StaticQueue::size</a></div><div class="ttdeci">int size(void)</div><div class="ttdoc">This function returns number of elements in queue. </div><div class="ttdef"><b>Definition:</b> erpc_static_queue.h:96</div></div>
<div class="ttc" id="classerpc_1_1_static_queue_html_ad10392812527307c0f7b411fd5ceb8ee"><div class="ttname"><a href="classerpc_1_1_static_queue.html#ad10392812527307c0f7b411fd5ceb8ee">erpc::StaticQueue::m_storage</a></div><div class="ttdeci">uint64_t m_storage[elementCount][(sizeof(T)+sizeof(uint64_t)-1)/                                                                                                                                           sizeof(uint64_t)]</div><div class="ttdef"><b>Definition:</b> erpc_static_queue.h:107</div></div>
<div class="ttc" id="namespaceerpc_html"><div class="ttname"><a href="namespaceerpc.html">erpc</a></div><div class="ttdef"><b>Definition:</b> erpc_arbitrated_client_manager.h:25</div></div>
<div class="ttc" id="classerpc_1_1_static_queue_html_ab1fe280f10fdf322ae75f16d80b812cc"><div class="ttname"><a href="classerpc_1_1_static_queue.html#ab1fe280f10fdf322ae75f16d80b812cc">erpc::StaticQueue::add</a></div><div class="ttdeci">bool add(T element)</div><div class="ttdoc">This function adds element to queue. </div><div class="ttdef"><b>Definition:</b> erpc_static_queue.h:61</div></div>
<div class="ttc" id="classerpc_1_1_static_queue_html_af18992edddaa6bfb26713fde997273b8"><div class="ttname"><a href="classerpc_1_1_static_queue.html#af18992edddaa6bfb26713fde997273b8">erpc::StaticQueue::m_tail</a></div><div class="ttdeci">uint32_t volatile m_tail</div><div class="ttdef"><b>Definition:</b> erpc_static_queue.h:111</div></div>
<div class="ttc" id="classerpc_1_1_static_queue_html_a24ddc2195588cee38e390652f9a6d070"><div class="ttname"><a href="classerpc_1_1_static_queue.html#a24ddc2195588cee38e390652f9a6d070">erpc::StaticQueue::~StaticQueue</a></div><div class="ttdeci">~StaticQueue(void)</div><div class="ttdoc">Destructor of StaticQueue class. </div><div class="ttdef"><b>Definition:</b> erpc_static_queue.h:52</div></div>
<div class="ttc" id="classerpc_1_1_static_queue_html"><div class="ttname"><a href="classerpc_1_1_static_queue.html">erpc::StaticQueue</a></div><div class="ttdoc">Template class which implements static queue as ring buffer. </div><div class="ttdef"><b>Definition:</b> erpc_static_queue.h:32</div></div>
<div class="ttc" id="classerpc_1_1_static_queue_html_a0c43f1fba589c88fbb22a0e8b237d58c"><div class="ttname"><a href="classerpc_1_1_static_queue.html#a0c43f1fba589c88fbb22a0e8b237d58c">erpc::StaticQueue::m_capacity</a></div><div class="ttdeci">uint32_t m_capacity</div><div class="ttdef"><b>Definition:</b> erpc_static_queue.h:109</div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- HTML footer for doxygen 1.8.5-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul class="foot">
    <li class="footer">Copyright 2016-2020 NXP Semiconductors. All rights reserved.
    </li>
  </ul>
</div>
</body>
</html>
